home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / MovingAnimation.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  1.9 KB  |  82 lines

  1. package symantec.itools.multimedia;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7.  
  8. public class MovingAnimation extends Animator implements Runnable {
  9.    int loopslot = 0;
  10.    int shiftOffset = 10;
  11.    private int curOffset = 0;
  12.  
  13.    public MovingAnimation() {
  14.       super.forever = true;
  15.    }
  16.  
  17.    public void setShiftOffset(int var1) {
  18.       this.shiftOffset = var1;
  19.    }
  20.  
  21.    public int getShiftOffset() {
  22.       return this.shiftOffset;
  23.    }
  24.  
  25.    public void run() {
  26.       Thread.currentThread().setPriority(4);
  27.       Dimension var1 = ((Component)this).size();
  28.       int var2 = super.images.size();
  29.       if (var2 > 1) {
  30.          if (this.shiftOffset < 0) {
  31.             this.curOffset = var1.width - super.maxWidth;
  32.          }
  33.  
  34.          int var3 = 0;
  35.  
  36.          while(true) {
  37.             if (++this.loopslot >= var2) {
  38.                ++var3;
  39.                if (var3 > super.numLoops && !super.forever) {
  40.                   break;
  41.                }
  42.  
  43.                this.loopslot = 0;
  44.                this.curOffset += this.shiftOffset;
  45.                if (this.curOffset < 0) {
  46.                   this.curOffset = var1.width - super.maxWidth;
  47.                } else if (this.curOffset + super.maxWidth > var1.width) {
  48.                   this.curOffset = 0;
  49.                }
  50.             }
  51.  
  52.             ((Component)this).repaint();
  53.  
  54.             try {
  55.                Thread.sleep((long)super.delay);
  56.             } catch (InterruptedException var4) {
  57.                return;
  58.             }
  59.          }
  60.       }
  61.  
  62.    }
  63.  
  64.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  65.       if ((var2 & 56) != 0 && super.images != null && this.loopslot < super.images.size() && ((AnimatorImage)super.images.elementAt(this.loopslot)).image == var1) {
  66.          ((Component)this).repaint(100L);
  67.       }
  68.  
  69.       return (var2 & 96) == 0;
  70.    }
  71.  
  72.    public void paint(Graphics var1) {
  73.       if (super.images != null && this.loopslot < super.images.size()) {
  74.          Image var2 = ((AnimatorImage)super.images.elementAt(this.loopslot)).image;
  75.          if (var2 != null) {
  76.             var1.drawImage(var2, this.curOffset, 0, this);
  77.          }
  78.       }
  79.  
  80.    }
  81. }
  82.